package be.jaisy.project.adapter.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Expression;

import be.jaisy.adapter.hibernate.GenericDao;
import be.jaisy.project.adapter.IProjectDao;
import be.jaisy.project.adapter.domain.Project;

public class ProjectDaoImpl extends GenericDao<Project, String> implements IProjectDao {
	
	public ProjectDaoImpl(String sessionFactoryId) {
		super(sessionFactoryId);		
	}

	@SuppressWarnings("unchecked")
	public Project findByName(String name, boolean lock) {
		Criteria crit = getSession().createCriteria(getPersistentClass());
		crit.add(Expression.eq( "name", name ));
		List<Project> projects = crit.list();
		if(projects ==null || projects.size()==0)
			return null;		
		return projects.get(0);
	}

}
